<?php

namespace App\Jobs;

use App\Model\ChangeVar;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;


class Testqueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $list = [];

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($list)
    {
        if(empty($list)) throw new \Exception('数组不能为空');
        $this->list = $list;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        foreach ($this->list as $list){
            $change_after = strtoupper($list);
            $data = [
                'change_before'=>$list,
                'change_after'=>$change_after,
            ];
            try{
                $model = new ChangeVar;
                $model->insert($data);
            }catch(\Exception $e){
                dd($e->getMessage());
            }


        }
    }
}
